package my.multithreadtest;

public class InvariantWatcher extends Thread {
	private Invariant invariant;
	public InvariantWatcher(Invariant invariant){
		this.invariant=invariant;
		setDaemon(true);
		start();
	}
	//public InvariantWatcher(Invariant invariant , final int timeout){
	public void run(){
		while(true){
			InvariantState state=invariant.invariant();
			if(state instanceof InvariantFailure){
				System.out.println("Invaritant violated: " + ((InvariantFailure)state).value);
				System.exit(0);
			}
		}
	}
}
